; 002.c 

global _main

section .data
LC0:
	db "please input the decimalism number(0~32767):",0Ah,0
	
LC1:
	db "%d",0
	
LC2:
	db " ",0

extern _memset,_printf,_scanf
section .text
_main:
	push ebp
	mov ebp,esp
	sub esp,0x1000
	
	mov dword [ebp-0x1000],0 ; i
	mov dword [ebp-0xffc],0 ; j
	mov dword [ebp-0xff8],0 ; n
	mov dword [ebp-0xff4],0 ; m
	mov dword [ebp-0xff0],0 ; a 
	
	mov dword [esp+8],64
	mov dword [esp+4],0
	lea eax,[ebp-0xff0] ; a
	mov [esp+0],eax 
	call _memset

	mov dword [esp+0],LC0
	mov eax,0 
	call _printf 
	sub esp,4
	
	lea eax,[ebp-0xff8] ; n 
	mov dword [esp+4],eax 
	mov dword [esp+0],LC1
	mov eax,0
	call _scanf 
	sub esp,8
	
	mov dword [ebp-0xff4],0 ;m 
	jmp .Lmain_400
	
.Lmain_500:
	mov eax,dword [ebp-0xff8] ; n 
	mov ebx,2
	xor edx,edx
	idiv ebx 
	mov [ebp-0x1000],edx ; i 
	
	mov eax,dword [ebp-0xff8] ; n 
	mov ebx,2
	xor edx,edx
	idiv ebx 
	mov [ebp-0xffc],eax ; j 
	
	mov eax,dword [ebp-0xffc] ; j 
	mov [ebp-0xff8],eax ; n 
	
	mov ecx,[ebp-0x1000] ; i 
	mov eax,[ebp-0xff4] ; m 
	sal eax,2
	lea edi,[ebp-0xff0] ; a 	
	mov [edi+eax],ecx ; a[m] 
	
	add dword [ebp-0xff4],1
	
.Lmain_400:
	cmp dword [ebp-0xff4], 15 ; m 
	jl .Lmain_500
	
	mov dword [ebp-0xff4],15 ; m 
	jmp .Lmain_300
	
.Lmain_390:
	mov eax,[ebp-0xff4] ; m 
	sal eax,2
	lea edi,[ebp-0xff0] ; a 
	mov eax,[edi+eax] ; a[m] 
	mov dword [esp+4],eax
	mov dword [esp+0],LC1
	mov eax,0
	call _printf 
	
	mov eax,[ebp-0xff4] ; m 
	mov ebx,4
	xor edx,edx
	idiv ebx
	cmp edx,0
	jne .Lmain_350
	
	mov dword [esp+0],LC2 
	mov eax,0
	call _printf 
	
.Lmain_350:
	sub dword [ebp-0xff4],1 ; m 
	
.Lmain_300:
	cmp dword [ebp-0xff4],0
	jge .Lmain_390 
	
	mov eax,0
	leave
	ret 